package com.xbongbong.paas.pojo.dto;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.toolbox.wrap.BaseDTO;
import com.xbongbong.paas.toolbox.wrap.QueryIgnore;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.pro.formdata.pojo.SaasNeedRedundantAttrPojo;
import com.xbongbong.pro.user.pojo.ReturnUserAndDepartmentPojo;
import com.xbongbong.saas.domain.entity.DistributorBaseInfoEntity;
import com.xbongbong.saas.domain.entity.OnlinePaymentFlowEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * @author: wufeng
 * @date: 2018/9/6 15:24
 * @desrcption: 保存表单数据
 */
@Getter
@Setter
@ToString
public class FormDataAddDTO extends BaseDTO {

    private static final long serialVersionUID = 890245517899327058L;

    @NotNull(message = "{dto.msg.formDataAdd.formId.NotNull}")
    private Long formId;

    @NotNull(message = "{dto.msg.formDataAdd.appId.NotNull}")
    private Long appId;

    @NotNull(message = "{dto.msg.formDataAdd.menuId.NotNull}")
    @Getter(onMethod_ = {@QueryIgnore})
    private Long menuId;

    /**
     * 编号，流水号
     */
    @Length(max = 50, message = "{dto.msg.formDataAdd.serialNo.Length}")
    private String serialNo;
    /**
     * 组号
     */
    private String groupNumber;
    /**
     * 负责人
     */
    private List<ReturnUserAndDepartmentPojo> ownerId;
    /**
     * 协同人
     */
    private List<ReturnUserAndDepartmentPojo> coUserId;
    /**
     * 可见部门集合
     */
    private List<Object> visbleDept;
    /**
     * 可见人集合
     */
    private List<Object> visbleUser;

    /**
     * 所属部门
     */
    private Long departmentId;
    /**
     *关联客户id
     */
    private List<Integer> dataIdList;

    @NotEmpty(message = "{dto.msg.formDataAdd.dataList.NotEmpty}")
    private JSONObject dataList;
    /**
     * saas标记
     * TODO  后面应该限制非空
     */
    @Min(value = 1)
    @Max(value = 2)
    @NotNull(message = "saasMark {javax.validation.constraints.NotNull.message}" )
    private Integer saasMark;
    /**
     * saas业务类型
     */
    @Getter(onMethod_ = {@QueryIgnore})
//    @NotNull(message = "businessType {javax.validation.constraints.NotNull.message}" )
    private Integer businessType;

    /**
     * saas子业务类型
     */
    @Getter(onMethod_ = {@QueryIgnore})
    private Integer subBusinessType;

    /**
     * saas所需的特殊传参pojo
     */
    @Valid
    private SaasNeedRedundantAttrPojo saasNeedRedundantAttrPoJo;

    /**
     * 是否是导入 1是导入
     */
    @Getter(onMethod_ = {@QueryIgnore})
    private Integer isImport;
    /**
     * 字段容器
     */
    @Getter(onMethod_ = {@QueryIgnore})
    private Map<String, FieldAttrEntity> explainMap;

    /**
     * 流程创建人id
     */
    private String processCreatorId;
    /**
     * 是否是从业务规则来的 1：是
     */
    @Getter(onMethod_ = {@QueryIgnore})
    private Integer isBusinessRule;

    /**
     * 部分字段导入
     */
    @Getter(onMethod_ = {@QueryIgnore})
    private List<String> attrList;

    /**
     * 资金管理中 金额明细详情
     */
    private JSONArray amountDetail;
    
    private Boolean isTotalPaymentSheetAmount;
    
    private Integer isOldProgressData;
    /**
     * 是否外链新建
     */
    private Integer fromOuterLink;

    // ===============================
    /**
     * 线索转换客户操作，下面的是否要将销售线索的跟进记录自动带入客户按钮
     */
    private Integer isBringCustomer;
    private Long clueId;
    /**
     * 在线支付流水信息
     */
    private OnlinePaymentFlowEntity onlinePaymentFlowEntity;

    /**
     * 经销商基础信息信息
     */
    private DistributorBaseInfoEntity distributorBaseInfoEntity;
    // ===============================
    
    
    /**
     * 是否符合触发
     */
    private Boolean isSatisfyTrigger = false;
    /**
     * 符合触发类型的list
     * 类型WorkflowEntity 引不到
     */
    private List workflowEntityList;

    /**
     * 知识库-知识库ID
     */
    private Long knowledgeBaseId;
    /**
     *  是否批量操作  0 否 1是
     */
    private Integer isBatch;

    /**
     * 群id，发送审批卡片到群（酷应用）
     */
    private String openConversationId;

    /**
     * 代表是进审批。这个字段主要是为了给合同+回款单、预收款/采购合同+付款单、预付款下游单据审批状态增加
     */
    private Boolean fromApproval;

    /**
     * 跟进提醒需要关联的数据id
     */
    private Long notifyNeedDataId;

    /**
     * 需要查重的电话
     */
    private List<String> fineCluePhone;

    public FormDataAddDTO(){
        departmentId = 0L;
        saasNeedRedundantAttrPoJo = new SaasNeedRedundantAttrPojo();
        isImport = 0;
    }
    public FormDataAddDTO(Long formId, Long appId, Long menuId, JSONObject dataList, Integer saasMark, Integer businessType,
                              UserVO userVO, String corpid, String httpHeader) {
        this.formId = formId;
        this.appId = appId;
        this.menuId = menuId;
        this.dataList = dataList;
        this.saasMark = saasMark;
        this.businessType = businessType;
        setLoginUser(userVO);
        setCorpid(corpid);
        setLoginUserName(userVO.getName());
        setUserId(userVO.getUserId());
        setHttpHeader(httpHeader);
    }
}
